package me.minecraft.woodenman.command;

import me.minecraft.woodenman.WoodenMan;
import me.minecraft.woodenman.config.Language;
import me.minecraft.woodenman.runnable.GameTask;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

/**
 * @author langle__
 * @version 1.0
 */
public class CreateCommand extends SubCommand {

    @Override
    public String getName() {
        return "create";
    }

    @Override
    public void onCommand(CommandSender sender, String[] args) {
        if (WoodenMan.gameTask != null) {
            sender.sendMessage(Language.GAME_ALREADY_EXISTS);
            return;
        }
        sender.sendMessage(Language.GAME_CREATED);
        TextComponent text_1 = new TextComponent(Language.PREFIX + " 有人举办了一场游戏 ");
        TextComponent text_2 = new TextComponent("§7[§b点击加入游戏§7]");
        text_2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/wmjoin"));
        Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(text_1, text_2));
        WoodenMan.gameTask = new GameTask();
    }

}
